﻿namespace AppLab.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Data;
    using System.IO;
    using System.Linq;
    using System.ServiceModel;
    using System.ServiceModel.Activation;
    using System.ServiceModel.DomainServices.EntityFramework;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using System.Threading;
    using System.Web.Security;
    using AppLab.Data.Models;
    using AppLab.Web.Resources;
    using Wicresoft.AppFlow.Controls;
    using Wicresoft.AppFlow.Flows;

    // Implements application logic using the PMSEntities context.
    // TODO: Add your application logic to these methods or in additional methods.
    // TODO: Wire up authentication (Windows/ASP.NET Forms) and uncomment the following to disable anonymous access
    // Also consider adding roles to restrict access as appropriate.
    //[EnableClientAccess()]

    [EnableClientAccess]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class FlowService : DomainService
    {
        [Invoke(HasSideEffects = true)]
        public Guid Submit(SubmitData e)
        {
            Guid submitID = e.ToDataBase();
            //Guid submitID = new Controller().ExecuteFlow(Guid.Empty, e);
            e.SendEmail();
            return submitID;
        }

        [Invoke(HasSideEffects = true)]
        public Guid UpdateMobileBasicInfo(MobileBasicInfoData e)
        {
            e.UpadteMobileBasicInfoData();
            return Guid.NewGuid();
        }

        [Invoke(HasSideEffects = true)]
        public Guid AddMobileBasicInfo(MobileBasicInfoData e)
        {
            e.AddMobileBasicInfoData();
            return Guid.NewGuid();
        }

        [Invoke(HasSideEffects = true)]
        public Guid AddMobileBrand(Brand e)
        {
            e.AddMbBrand();
            return Guid.NewGuid();
        }

        [Invoke(HasSideEffects = true)]
        public bool ExistMbType(MobileType e)
        {
            return e.Exist();
        }

        [Invoke(HasSideEffects = true)]
        public Guid Review(Guid fid, ReviewSubmitData rsd)
        {
            //Thread.Sleep(1000);
            Guid reviewID = rsd.ToDataBase();
            // Guid reviewID = new Controller().ExecuteFlow(fid, rsd.ToDataBaseFormat());
            rsd.SendEmail();
            return reviewID;
        }

        [Invoke(HasSideEffects = true)]
        public Guid Task(Guid fid, TaskSubmitData tsd)
        {
            //Thread.Sleep(1000);
            Guid taskID = tsd.ToDataBase();
            //Guid taskID = new Controller().ExecuteFlow(fid, tsd.ToDataBaseFormat());
            tsd.SendEmail();
            return taskID;
        }

        [Invoke(HasSideEffects = true)]
        public Guid Publish(Guid fid, PublishSubmitData psd)
        {
            //return new Controller().ExecuteFlow(fid, psd.ToDataBaseFormat());
            return psd.ToDataBase();
        }

        /// <summary>
        /// Query method that exposes the <see cref="SubmitData"/> class to Silverlight client code.
        /// </summary>
        /// <remarks>
        /// This query method is not used and will throw <see cref="NotSupportedException"/> if called.
        /// Its primary job is to indicate the <see cref="SubmitData"/> class should be made
        /// available to the Silverlight client.
        /// </remarks>
        /// <returns>Not applicable.</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public IEnumerable<SubmitData> GetSubmits()
        {
            throw new NotSupportedException();
        }

        public IEnumerable<SubmitType> GetSubmitTypes()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.tysx_SubmitType
                             select new SubmitType()
                             {
                                 SubmitTypeId = t.SubmitTypeID,
                                 SubmitTypeName = t.SubmitTypeName,
                             };
                return source.ToArray();
            }
        }

        public IEnumerable<Brand> GetBrands()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MobileBrands
                             orderby t.BrandName
                             select new Brand()
                             {
                                 BrandId = t.BrandID,
                                 BrandName = t.BrandName,
                                 BrandNameEN = t.BrandNameEN,
                                 BrandNameEN1 = t.BrandNameEN1,
                                 BrandNameEN2 = t.BrandNameEN2,
                             };
                return source.ToArray();
            }
        }


        #region 手机型号

        //判断该手机型号是否存在
        public bool IExistMobileType(string type)
        {
            using (var dc = PMSEntities.Create())
            {
                return dc.MobileBasicInfoes.Where(p => p.MobileType == type).Count() > 0 ? true : false;
            }
        }

        public IEnumerable<MobileType> GetMobileTypes(int brandId)
        {
            using (var dc = PMSEntities.Create())
            {
                if (brandId > 0)
                {
                    //指定品牌手机型号
                    var source = from t in dc.MobileBasicInfoes
                                 where t.BrandID == brandId
                                 orderby t.MobileType
                                 select new MobileType()
                                 {
                                     MobileId = t.MobileID,
                                     TypeName = t.MobileType
                                 };
                    return source.ToArray();
                }
                else
                {
                    //所有手机型号
                    var source = from t in dc.MobileBasicInfoes
                                 orderby t.MobileType
                                 select new MobileType()
                                 {
                                     TypeName = t.MobileType,
                                     MobileId = t.MobileID
                                 };
                    return source.ToArray();
                }
            }
        }

        #endregion

        public IEnumerable<MediaClient> GetMediaClient(int TerminalId)
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.tysx_MediaClient
                             where t.TerminalID == TerminalId
                             orderby t.MediaClientID
                             select new MediaClient()
                             {
                                 MediaClientId = t.MediaClientID,
                                 MediaClientName = t.MediaClientName,
                                 MediaClientVersion = t.MediaClientVersion
                             };
                return source.ToArray();
            }
        }

        [Invoke(HasSideEffects = true)]
        public MediaClient GetMediaClient2(int TerminalId)
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.tysx_MediaClient
                             //TO DO：将来这个可能需要加入是否发布这个条件
                             where t.TerminalID == TerminalId
                             orderby t.MediaClientID descending
                             select new MediaClient()
                             {
                                 MediaClientId = t.MediaClientID,
                                 MediaClientName = t.MediaClientName
                             };
                try
                {
                    return source.First();
                }
                catch
                {
                    return null;
                }
            }
        }

        public IEnumerable<Category> GetCategorys()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MobileCategories
                             select new Category()
                             {
                                 CategoryID = t.CategoryID,
                                 CategoryName = t.Category
                             };
                return source.ToArray();
            }
        }

        public IEnumerable<CPU> GetCPUs()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MobileCPUs
                             orderby t.CPUSIZE
                             select new CPU()
                             {
                                 CPUID = t.CPUID,
                                 CPUSize = t.CPUSIZE
                             };
                return source.ToArray();
            }
        }

        public IEnumerable<ScreenSize> GetScreenSizes()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MobileScreenSizes
                             orderby t.ScreenSizeID
                             select new ScreenSize()
                             {
                                 ScreenSizeID = t.ScreenSizeID,
                                 ScreenSizeType = t.ScreenSizeType
                             };
                return source.ToArray();
            }
        }

        public IEnumerable<Resolution> GetResolutions()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MobileResolutions
                             orderby t.Resolution
                             select new Resolution()
                             {
                                 ResolutionID = t.ResolutionID,
                                 ResolutionSize = t.Resolution
                             };
                return source.ToArray();
            }
        }

        #region 操作系统
        public IEnumerable<OS> GetOSs()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MobileOS
                             orderby t.OSName
                             select new OS()
                             {
                                 OSID = t.OSID,
                                 OSName = t.OSName
                             };
                return source.ToArray();
            }
        }

        [Invoke(HasSideEffects = true)]
        public OS GetOS2(int TerminalId)
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MobileOS
                             where t.OSID == dc.MobileBasicInfoes.FirstOrDefault(p => p.MobileID == TerminalId).OSID
                             select new OS()
                             {
                                 OSID = t.OSID,
                                 OSName = t.OSName
                             };
                return source.First();
            }
        }
        #endregion
        public IEnumerable<Platform> GetPlatforms()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MobilePlatforms
                             orderby t.PlatformName
                             select new Platform()
                             {
                                 PlatformID = t.PlatformID,
                                 PlatformName = t.PlatformName
                             };
                return source.ToArray();
            }
        }

        public IEnumerable<OutwardType> GetOutwardTypes()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MobileOutwardTypes
                             orderby t.OutwardTypeName
                             select new OutwardType()
                             {
                                 OutwardTypeID = t.OutwardTypeID,
                                 OutwardTypeName = t.OutwardTypeName
                             };
                return source.ToArray();
            }
        }

        # region 手机信息

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public IEnumerable<MobileBasicInfoData> GetMoblieBasicInfo()
        {
            throw new NotSupportedException();
        }

        public int GetMobileBasicInfoCount(int brandID, string type)
        {
            using (var dc = PMSEntities.Create())
            {
                if (brandID > 0)
                {
                    return dc.MobileBasicInfoes.Where(p => p.BrandID == brandID).Count();
                }
                else if (!string.IsNullOrEmpty(type))
                {
                    return dc.MobileBasicInfoes.Where(p => p.MobileType.Contains(type)).Count();
                }
                else
                {
                    return dc.MobileBasicInfoes.Count();
                }
            }
        }

        public bool ModifyEnable(int mobileID)
        {
            using (var dc = PMSEntities.Create())
            {
                return dc.tysx_MediaClient.Where(p => p.TerminalID == mobileID).Count() > 0 ? true : false;
            }
        }

        public IEnumerable<MobileBasicInfoData> GetMobileBasicInfoOnPage(int pageSize, int pageIndex, int brandID, string type)
        {
            using (var dc = PMSEntities.Create())
            {
                string strFilter = string.Empty;
                if (brandID > 0) strFilter = string.Format(" and it.BrandID={0}", brandID);
                else if (!string.IsNullOrEmpty(type)) strFilter = string.Format(" and it.MobileType like '%{0}%'", type);

                var query = from mbi in dc.MobileBasicInfoes.Where("True " + strFilter)
                            select new MobileBasicInfoData
                            {
                                FlowGuid = Guid.NewGuid(),
                                MobileID = mbi.MobileID,

                                MobileBrand = mbi.MobileBrand.BrandName,
                                MobileType = mbi.MobileType,

                                MobileOS = dc.MobileOS.FirstOrDefault(p => p.OSID == mbi.OSID).OSName,
                                Resoulution = dc.MobileResolutions.FirstOrDefault(p => p.ResolutionID == mbi.ResolutionID).Resolution,
                                ScreenSize = dc.MobileScreenSizes.FirstOrDefault(p => p.ScreenSizeID == mbi.ScreenSizeID).ScreenSizeType,
                                OutwardTypeStr = dc.MobileOutwardTypes.FirstOrDefault(p => p.OutwardTypeID == mbi.OutwardTypeID).OutwardTypeName,

                                IsOn3G = dc.MobileBaseStatus.FirstOrDefault(p => p.StatusID == mbi.IS3G).Status,
                                IsOnStreamMedia = dc.MobileBaseStatus.FirstOrDefault(p => p.StatusID == mbi.StreamMedia_ID).Status,
                                IsOnTouch = dc.MobileBaseStatus.FirstOrDefault(p => p.StatusID == mbi.Touch_ID).Status,

                                InformationTime = mbi.InformationTime,

                                BrandID = mbi.BrandID,

                                CategoryID = (int)mbi.CategoryID,
                                CPUID = (int)mbi.CPUID,
                                PlatformID = (int)mbi.PlatformID,
                                OSID = (int)mbi.OSID,
                                ScreenSizeID = (int)mbi.ScreenSizeID,
                                ResoulutionID = (int)mbi.ResolutionID,
                                OutwardTypeID = mbi.OutwardTypeID.HasValue ? mbi.OutwardTypeID.Value : 0,
                                Is3G = (int)mbi.IS3G,
                                IsStreamMedia = (int)mbi.StreamMedia_ID,
                                IsTouch = (int)mbi.Touch_ID,
                                Prince = mbi.Price.HasValue ? mbi.Price.Value : 0,
                            };
                query = query.OrderByDescending(p => p.MobileID).Skip(pageSize * pageIndex).Take(pageSize);

                return query.ToList();
            }
        }

        #endregion

        #region 浏览

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public IEnumerable<HistoryData> GetHistory()
        {
            throw new NotSupportedException();
        }

        public int GetMobileVersionsCount(int mobileID)
        {
            using (var dc = PMSEntities.Create())
            {
                return dc.tysx_MediaClient.Where(p => p.TerminalID == mobileID).Count();
            }
        }

        public IEnumerable<HistoryData> GetVersionsDataGrid(int mobileID, int pageSize, int pageIndex)
        {
            //如果数据库中，时间格式的值为空，则会返回"1/1/001"错误时间
            using (var dc = PMSEntities.Create())
            {
                var query = from e in dc.tysx_Submit.Where(p => p.tysx_MediaClient.TerminalID == mobileID)
                            select new HistoryData()
                            {
                                FlowGuid = dc.tysx_AppFlow.FirstOrDefault(p => p.SubmitID == e.SubmitID).FlowID,
                                MobileType = e.tysx_MediaClient.MobileBasicInfo.MobileType,
                                MoblieBrandAndType = e.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName + "(" + e.tysx_MediaClient.MobileBasicInfo.MobileType + ")",
                                MediaClientID = (int)e.MediaClientID,
                                MobileVersion = e.tysx_MediaClient.MediaClientVersion,
                                SubmitBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.SubmitBy).DisplayName,
                                SubmitTime = (DateTime)e.SubmitTime,
                                SubmitType = e.tysx_SubmitType.SubmitTypeName,
                                SubmitPackage = e.tysx_MediaClient.MediaClientName,
                                SubmitReleaseNote = e.ReleaseNotesName,
                                SubmitSelfTest = e.InsideCompatiableTestReportName,
                                SubmitAnythingElse = e.AnythingElseName,
                                SubmitComment = e.SubmitComment,
                                ReviewBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Review.ReviewBy).DisplayName,
                                ReviewEndTime = e.tysx_Review.ReviewTime,
                                Priority = e.tysx_Review.tysx_TestTask.Priority,
                                AssignedTo = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Review.tysx_TestTask.AssignedTo).DisplayName,
                                TestTaskEAT = e.tysx_Review.tysx_TestTask.TestTaskETA,
                                TestEndTime = e.tysx_Review.tysx_TestTask.EndDate,
                                State = dc.tysx_AppFlow.FirstOrDefault(p => p.SubmitID == e.SubmitID).StateID,
                                InspectionReport = e.tysx_Review.tysx_TestTask.TestReportName,
                                SpectionReport = e.tysx_Review.tysx_TestTask.TestReport != null,
                                AnythingElse = e.AnythingElse != null,
                                ReviewComment = e.tysx_Review.ReviewComment,
                                PublishedStr = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == mobileID).list,
                            };
                query = query.OrderByDescending(p => p.MediaClientID).Skip(pageSize * pageIndex).Take(pageSize);
                return query.ToList();
            }
        }
        #endregion

        #region 审核

        /// <summary>
        /// Query method that exposes the <see cref="SubmitData"/> class to Silverlight client code.
        /// </summary>
        /// <remarks>
        /// This query method is not used and will throw <see cref="NotSupportedException"/> if called.
        /// Its primary job is to indicate the <see cref="SubmitData"/> class should be made
        /// available to the Silverlight client.
        /// </remarks>
        /// <returns>Not applicable.</returns>
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public IEnumerable<ReviewSubmitData> GetReviews()
        {
            throw new NotSupportedException();
        }

        public int GetReviewCount()
        {
            using (var dc = PMSEntities.Create())
            {
                return dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingReview).Count();
            }
        }

        public IEnumerable<ReviewSubmitData> GetReviewDataGrid(int pageSize, int pageIndex)
        {
            using (var dc = PMSEntities.Create())
            {
                var query = from e in dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingReview)
                            select new ReviewSubmitData()
                            {
                                FlowGuid = e.FlowID,
                                MobileBrand = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName,
                                MobileType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType,
                                MoblieBrandAndType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName + "(" + e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType + ")",
                                SubmitByAlias = e.tysx_Submit.SubmitBy,
                                SubmitBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.SubmitBy).DisplayName,
                                SubmitTime = (DateTime)e.tysx_Submit.SubmitTime,
                                SubmitType = e.tysx_Submit.tysx_SubmitType.SubmitTypeName,
                                SubmitPackage = e.tysx_Submit.tysx_MediaClient.MediaClientName,
                                SubmitUpgradePackage = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientName,
                                MobileVersion = e.tysx_Submit.tysx_MediaClient.MediaClientVersion,
                                SubmitReleaseNote = e.tysx_Submit.ReleaseNotesName,
                                SubmitSelfTest = e.tysx_Submit.InsideCompatiableTestReportName,
                                SubmitAnythingElse = e.tysx_Submit.AnythingElseName,
                                AnythingElse = e.tysx_Submit.AnythingElse != null,
                                UpgradePackageEnable = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientPackage != null,
                                SubmitComment = e.tysx_Submit.SubmitComment,
                                MediaClientID = (int)e.tysx_Submit.MediaClientID,
                                RowGuid = e.tysx_Submit.RowGuid,
                            };
                query = query.OrderByDescending(p => p.MediaClientID).Skip(pageSize * pageIndex).Take(pageSize);
                return query.ToList();
            }
        }

        #endregion

        #region 验收

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public IEnumerable<TaskSubmitData> GetTasks()
        {
            throw new NotSupportedException();
        }

        public int GetTaskCount(string type)
        {
            using (var dc = PMSEntities.Create())
            {
                //string strFilter = string.Format(" it.StateID == {0}", (int)FlowState.PendingTest);
                //if (!string.IsNullOrEmpty(type)) strFilter = strFilter + string.Format(" and it.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType like '%{0}%'", type);
                //return dc.tysx_AppFlow.Where("True " + strFilter).Count();

                if (!string.IsNullOrEmpty(type))
                {
                    return dc.tysx_AppFlow.Where(p => p.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType.Contains(type)
                        && p.StateID == (int)FlowState.PendingTest).Count();
                }
                else
                {
                    return dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingTest).Count();
                }
            }
        }

        //public int GetTaskCount()
        //{
        //    using (var dc = PMSEntities.Create())
        //    {
        //        return dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingTest).Count();
        //    }
        //}

        //public int GetTaskCount(string alias)
        //{
        //    using (var dc = PMSEntities.Create())
        //    {
        //        if (String.IsNullOrEmpty(alias))
        //        {
        //            return dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingTest).Count();
        //        }
        //        else
        //        {
        //            return dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingTest && p.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo == alias).Count();
        //        }
        //    }
        //}

        public IEnumerable<TaskSubmitData> GetTaskDataGrid(int pageSize, int pageIndex, string type)
        {
            using (var dc = PMSEntities.Create())
            {
                if (string.IsNullOrEmpty(type))
                {
                    var query = from e in dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingTest)
                                select new TaskSubmitData()
                                {
                                    FlowGuid = e.FlowID,
                                    MobileBrand = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName,
                                    MobileType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType,
                                    MoblieBrandAndType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName + "(" + e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType + ")",
                                    SubmitByAlias = e.tysx_Submit.SubmitBy,
                                    SubmitBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.SubmitBy).DisplayName,
                                    SubmitTime = (DateTime)e.tysx_Submit.SubmitTime,
                                    SubmitType = e.tysx_Submit.tysx_SubmitType.SubmitTypeName,
                                    SubmitPackage = e.tysx_Submit.tysx_MediaClient.MediaClientName,
                                    SubmitUpgradePackage = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientName,
                                    MobileVersion = e.tysx_Submit.tysx_MediaClient.MediaClientVersion,
                                    SubmitReleaseNote = e.tysx_Submit.ReleaseNotesName,
                                    SubmitSelfTest = e.tysx_Submit.InsideCompatiableTestReportName,
                                    SubmitAnythingElse = e.tysx_Submit.AnythingElseName,
                                    SubmitComment = e.tysx_Submit.SubmitComment,
                                    MediaClientID = (int)e.tysx_Submit.MediaClientID,
                                    RowGuid = e.tysx_Submit.RowGuid,
                                    AnythingElse = e.tysx_Submit.AnythingElse != null,
                                    UpgradePackageEnable = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientPackage != null,
                                    TestTypeID = (int)e.tysx_Submit.SubmitTypeID,
                                    StartTime = (DateTime)e.tysx_Submit.tysx_Review.ReviewTime,
                                    TestTaskEAT = (DateTime)e.tysx_Submit.tysx_Review.tysx_TestTask.TestTaskETA,
                                    Priority = (int)e.tysx_Submit.tysx_Review.tysx_TestTask.Priority,
                                    ReviewBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.ReviewBy).DisplayName,
                                    AssignedTo = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo).DisplayName,
                                    AssignedToAlias = e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo,
                                };
                    query = query.OrderByDescending(p => p.MediaClientID).Skip(pageSize * pageIndex).Take(pageSize);
                    return query.ToList();
                }
                else
                {
                    var query = from e in dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingTest
                                    && p.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType.Contains(type))
                                select new TaskSubmitData()
                                {
                                    FlowGuid = e.FlowID,
                                    MobileBrand = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName,
                                    MobileType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType,
                                    MoblieBrandAndType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName + "(" + e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType + ")",
                                    SubmitByAlias = e.tysx_Submit.SubmitBy,
                                    SubmitBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.SubmitBy).DisplayName,
                                    SubmitTime = (DateTime)e.tysx_Submit.SubmitTime,
                                    SubmitType = e.tysx_Submit.tysx_SubmitType.SubmitTypeName,
                                    SubmitPackage = e.tysx_Submit.tysx_MediaClient.MediaClientName,
                                    SubmitUpgradePackage = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientName,
                                    MobileVersion = e.tysx_Submit.tysx_MediaClient.MediaClientVersion,
                                    SubmitReleaseNote = e.tysx_Submit.ReleaseNotesName,
                                    SubmitSelfTest = e.tysx_Submit.InsideCompatiableTestReportName,
                                    SubmitAnythingElse = e.tysx_Submit.AnythingElseName,
                                    SubmitComment = e.tysx_Submit.SubmitComment,
                                    MediaClientID = (int)e.tysx_Submit.MediaClientID,
                                    RowGuid = e.tysx_Submit.RowGuid,
                                    AnythingElse = e.tysx_Submit.AnythingElse != null,
                                    UpgradePackageEnable = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientPackage != null,
                                    TestTypeID = (int)e.tysx_Submit.SubmitTypeID,
                                    StartTime = (DateTime)e.tysx_Submit.tysx_Review.ReviewTime,
                                    TestTaskEAT = (DateTime)e.tysx_Submit.tysx_Review.tysx_TestTask.TestTaskETA,
                                    Priority = (int)e.tysx_Submit.tysx_Review.tysx_TestTask.Priority,
                                    ReviewBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.ReviewBy).DisplayName,
                                    AssignedTo = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo).DisplayName,
                                    AssignedToAlias = e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo,
                                };
                    query = query.OrderByDescending(p => p.MediaClientID).Skip(pageSize * pageIndex).Take(pageSize);
                    return query.ToList();
                }
            }
        }

        //public IEnumerable<TaskSubmitData> GetTaskDataGrid(int pageSize, int pageIndex, string alias)
        //{
        //    using (var dc = PMSEntities.Create())
        //    {
        //        //if (dc.vw_userInRoles.FirstOrDefault(p => p.Alias == alias && p.RoleName == "Tester Leader") != null || String.IsNullOrEmpty(alias))
        //        if (String.IsNullOrEmpty(alias))
        //        {
        //            var query = from e in dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingTest)
        //                        select new TaskSubmitData()
        //                        {
        //                            FlowGuid = e.FlowID,
        //                            MobileBrand = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName,
        //                            MobileType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType,
        //                            MoblieBrandAndType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName + "(" + e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType + ")",
        //                            SubmitByAlias = e.tysx_Submit.SubmitBy,
        //                            SubmitBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.SubmitBy).DisplayName,
        //                            SubmitTime = (DateTime)e.tysx_Submit.SubmitTime,
        //                            SubmitType = e.tysx_Submit.tysx_SubmitType.SubmitTypeName,
        //                            SubmitPackage = e.tysx_Submit.tysx_MediaClient.MediaClientName,
        //                            SubmitUpgradePackage = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientName,
        //                            MobileVersion = e.tysx_Submit.tysx_MediaClient.MediaClientVersion,
        //                            SubmitReleaseNote = e.tysx_Submit.ReleaseNotesName,
        //                            SubmitSelfTest = e.tysx_Submit.InsideCompatiableTestReportName,
        //                            SubmitAnythingElse = e.tysx_Submit.AnythingElseName,
        //                            SubmitComment = e.tysx_Submit.SubmitComment,
        //                            MediaClientID = (int)e.tysx_Submit.MediaClientID,
        //                            RowGuid = e.tysx_Submit.RowGuid,
        //                            AnythingElse = e.tysx_Submit.AnythingElse != null,
        //                            UpgradePackageEnable = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientPackage != null,
        //                            TestTypeID = (int)e.tysx_Submit.SubmitTypeID,
        //                            StartTime = (DateTime)e.tysx_Submit.tysx_Review.ReviewTime,
        //                            TestTaskEAT = (DateTime)e.tysx_Submit.tysx_Review.tysx_TestTask.TestTaskETA,
        //                            Priority = (int)e.tysx_Submit.tysx_Review.tysx_TestTask.Priority,
        //                            ReviewBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.ReviewBy).DisplayName,
        //                            AssignedTo = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo).DisplayName,
        //                            AssignedToAlias = e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo,
        //                        };
        //            query = query.OrderBy(p => p.FlowGuid).Skip(pageSize * pageIndex).Take(pageSize);
        //            return query.ToList();
        //        }
        //        else
        //        {
        //            var query = from e in dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.PendingTest && p.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo == alias)
        //                        select new TaskSubmitData()
        //                        {
        //                            FlowGuid = e.FlowID,
        //                            MobileBrand = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName,
        //                            MobileType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType,
        //                            MoblieBrandAndType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName + "(" + e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType + ")",
        //                            SubmitByAlias = e.tysx_Submit.SubmitBy,
        //                            SubmitBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.SubmitBy).DisplayName,
        //                            SubmitTime = (DateTime)e.tysx_Submit.SubmitTime,
        //                            SubmitType = e.tysx_Submit.tysx_SubmitType.SubmitTypeName,
        //                            SubmitPackage = e.tysx_Submit.tysx_MediaClient.MediaClientName,
        //                            SubmitUpgradePackage = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientName,
        //                            MobileVersion = e.tysx_Submit.tysx_MediaClient.MediaClientVersion,
        //                            SubmitReleaseNote = e.tysx_Submit.ReleaseNotesName,
        //                            SubmitSelfTest = e.tysx_Submit.InsideCompatiableTestReportName,
        //                            SubmitAnythingElse = e.tysx_Submit.AnythingElseName,
        //                            SubmitComment = e.tysx_Submit.SubmitComment,
        //                            MediaClientID = (int)e.tysx_Submit.MediaClientID,
        //                            RowGuid = e.tysx_Submit.RowGuid,
        //                            AnythingElse = e.tysx_Submit.AnythingElse != null,
        //                            UpgradePackageEnable = e.tysx_Submit.tysx_UpgradeMediaClient.UpgradeMediaClientPackage != null,
        //                            TestTypeID = (int)e.tysx_Submit.SubmitTypeID,
        //                            StartTime = (DateTime)e.tysx_Submit.tysx_Review.ReviewTime,
        //                            TestTaskEAT = (DateTime)e.tysx_Submit.tysx_Review.tysx_TestTask.TestTaskETA,
        //                            Priority = (int)e.tysx_Submit.tysx_Review.tysx_TestTask.Priority,
        //                            ReviewBy = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.ReviewBy).DisplayName,
        //                            AssignedTo = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo).DisplayName,
        //                            AssignedToAlias = e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo,
        //                        };
        //            query = query.OrderBy(p => p.FlowGuid).Skip(pageSize * pageIndex).Take(pageSize);
        //            return query.ToList();
        //        }
        //    }
        //}

        #endregion

        #region 发布

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public IEnumerable<PublishSubmitData> GetPublish()
        {
            throw new NotSupportedException();
        }

        public int GetPublicCount(string type)
        {
            using (var dc = PMSEntities.Create())
            {
                if (!string.IsNullOrEmpty(type))
                {
                    return dc.tysx_AppFlow.Where(p => p.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType.Contains(type)
                        && (p.StateID == (int)FlowState.TestSucceeded || p.StateID == (int)FlowState.PendingPublish)).Count();
                }
                else
                {
                    return dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.TestSucceeded || p.StateID == (int)FlowState.PendingPublish).Count();
                }
            }
        }

        //public int GetPublicCount()
        //{
        //    using (var dc = PMSEntities.Create())
        //    {
        //        return dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.TestSucceeded || p.StateID == (int)FlowState.PendingPublish).Count();
        //    }
        //}

        public IEnumerable<PublishSubmitData> GetPublicDataGrid(int pageSize, int pageIndex, string type)
        {
            using (var dc = PMSEntities.Create())
            {
                if (string.IsNullOrEmpty(type))
                {
                    var query = from e in dc.tysx_AppFlow.Where(p => p.StateID == (int)FlowState.TestSucceeded || p.StateID == (int)FlowState.PendingPublish)
                                select new PublishSubmitData()
                                {
                                    FlowGuid = e.FlowID,
                                    MobileID = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileID,
                                    MobileBrand = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName,
                                    MobileType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType,
                                    MobileVersion = e.tysx_Submit.tysx_MediaClient.MediaClientVersion,
                                    AssignedTo = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo).DisplayName,
                                    TestEndTime = (DateTime)e.tysx_Submit.tysx_Review.tysx_TestTask.EndDate,
                                    ReleaseState = (int)e.StateID == (int)FlowState.TestSucceeded ? "验收通过" : ((int)e.StateID == (int)FlowState.PendingPublish ? "保留意见" : string.Empty),
                                    WebState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("Web发布") ? 1 : 0,
                                    WapState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("Wap发布") ? 2 : 0,
                                    PreloadedState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("预装发布") ? 3 : 0,
                                    TysxSpaceState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("天翼空间") ? 4 : 0,
                                    TysxBoLuState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("天翼博路") ? 5 : 0,
                                };
                    query = query.OrderByDescending(p => p.TestEndTime).Skip(pageSize * pageIndex).Take(pageSize);
                    return query.ToList();
                }
                else
                {
                    var query = from e in dc.tysx_AppFlow.Where(p => p.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType.Contains(type)
                                    && (p.StateID == (int)FlowState.TestSucceeded || p.StateID == (int)FlowState.PendingPublish))
                                select new PublishSubmitData()
                                {
                                    FlowGuid = e.FlowID,
                                    MobileID = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileID,
                                    MobileBrand = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileBrand.BrandName,
                                    MobileType = e.tysx_Submit.tysx_MediaClient.MobileBasicInfo.MobileType,
                                    MobileVersion = e.tysx_Submit.tysx_MediaClient.MediaClientVersion,
                                    AssignedTo = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.tysx_Submit.tysx_Review.tysx_TestTask.AssignedTo).DisplayName,
                                    TestEndTime = (DateTime)e.tysx_Submit.tysx_Review.tysx_TestTask.EndDate,
                                    ReleaseState = (int)e.StateID == (int)FlowState.TestSucceeded ? "验收通过" : ((int)e.StateID == (int)FlowState.PendingPublish ? "保留意见" : string.Empty),
                                    WebState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("Web发布") ? 1 : 0,
                                    WapState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("Wap发布") ? 2 : 0,
                                    PreloadedState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("预装发布") ? 3 : 0,
                                    TysxSpaceState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("天翼空间") ? 4 : 0,
                                    TysxBoLuState = dc.vm_MobileRelease.FirstOrDefault(p => p.mobileid == e.tysx_Submit.tysx_MediaClient.TerminalID).list.Contains("天翼博路") ? 5 : 0,
                                };
                    query = query.OrderByDescending(p => p.TestEndTime).Skip(pageSize * pageIndex).Take(pageSize);
                    return query.ToList();
                }
            }
        }

        #endregion

        #region 根据SubmitTypeID获取SubmitType

        //return SubmitType from SubmitTypeID
        private string GetSubmitTypeFromSubmitTypeID(int id, PMSEntities dc)
        {
            if (dc == null)
                return string.Empty;
            try
            {
                return dc.tysx_SubmitType.First(p => p.SubmitTypeID == id).SubmitTypeName;
            }
            catch
            {
                return string.Empty;
            }
        }

        #endregion

        #region 获取全部系统用户

        public IEnumerable<Tester> GetAllUsers()
        {
            using (var dc = PMSEntities.Create())
            {
                return (from t in dc.vm_tysx_Testers
                        select new Tester
                        {
                            Alias = t.Alias,
                            DisplayName = t.DisplayName,
                        }).ToArray();
            }
        }

        #endregion

        # region 测试人员

        public IEnumerable<Tester> GetTester()
        {
            using (var dc = PMSEntities.Create())
            {
                return (from t in dc.vm_UsersInRole.Where(p => p.RoleName == UserRegistrationService.TaskRole)
                        select new Tester
                        {
                            Alias = t.Alias,
                            DisplayName = t.DisplayName,
                        }).ToArray();
            }
        }

        #endregion

        #region 获取当前角色是否包含该用户？

        public bool iUserInRole(int pageIndex, string userName)
        {
            UserRegistrationService ser = new UserRegistrationService();

            string[] list = Roles.GetUsersInRole(ser.GetRoleName(pageIndex));
            return list.Contains(userName, StringComparer.CurrentCultureIgnoreCase);
        }

        #endregion

        #region 角色列表

        public int GetUsersCount()
        {
            using (var dc = PMSEntities.Create())
            {
                return dc.aspnet_Users.Count();
            }
        }

        public IEnumerable<RolesForUser> GetRolesForUser()
        {
            List<RolesForUser> roles = new List<RolesForUser>();
            using (var dc = PMSEntities.Create())
            {
                List<aspnet_Membership> users = dc.aspnet_Membership.ToList();
                //List<aspnet_Users> users = dc.aspnet_Users.ToList();
                foreach (aspnet_Membership e in users)
                {
                    string[] list = Roles.GetRolesForUser(e.aspnet_Users.UserName);
                    RolesForUser role = new RolesForUser();

                    role.UserID = Guid.Parse(e.UserId);
                    role.Alias = e.aspnet_Users.UserName;
                    role.DisplayName = dc.vm_tysx_Testers.FirstOrDefault(p => p.Alias == e.aspnet_Users.UserName).DisplayName;
                    //role.IsRegister = list.Contains("Register") ? 1 : 0;
                    role.IsTerminalInfo = list.Contains(UserRegistrationService.TerminalInfoRole) ? 1 : 0;
                    role.IsHistory = list.Contains(UserRegistrationService.HistoryRole) ? 1 : 0;
                    role.IsSubmit = list.Contains(UserRegistrationService.SumbitRole) ? 1 : 0;
                    role.IsReview = list.Contains(UserRegistrationService.ReviewRole) ? 1 : 0;
                    role.IsTask = list.Contains(UserRegistrationService.TaskRole) ? 1 : 0;
                    role.IsPublish = list.Contains(UserRegistrationService.PublishRole) ? 1 : 0;
                    role.IsRole = list.Contains(UserRegistrationService.ManagementRole) ? 1 : 0;
                    roles.Add(role);
                }
            }
            return roles.OrderBy(p => p.Alias);
        }

        //修改角色
        [Invoke(HasSideEffects = true)]
        public bool RoleManagement(RolesForUser original, RolesForUser current)
        {
            return current.ToDataBaseFormat(original);
        }

        //重置密码
        [Invoke(HasSideEffects = true)]
        public bool ResetPassword(RolesForUser e, string resetManageName)
        {
            return e.ResetPassword(resetManageName);
        }

        //注销用户
        [Invoke(HasSideEffects = true)]
        public bool DeleteUser(RolesForUser e)
        {
            return e.DeleteUser();
        }

        #endregion


        #region 个人设置

        //暴露给客户端的接口
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public IEnumerable<PersonalSetting> PersonalSetting()
        {
            throw new NotSupportedException();
        }

        [Invoke(HasSideEffects = true)]
        public bool UserChangedSetting(bool which, PersonalSetting e)
        {
            if (which)
            {
                return e.ChangedPassword();
            }
            else
            {
                return e.ChangedEamil();
            }
        }

        #endregion

        // #region ResetPassword

        ////暴露给客户端的接口
        //[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        //public IEnumerable<ModifyPassword> ModifyPassword()
        //{
        //    throw new NotSupportedException();
        //}

        //[Invoke(HasSideEffects = true)]
        //public bool ResetPassword(RolesForUser e, string resetManageName)
        //{
        //    return e.ResetPassword(resetManageName);
        //}

        //[Invoke(HasSideEffects = true)]
        //public bool UserChangedPassword(ModifyPassword e)
        //{
        //    return e.ChangePassword();
        //}
        //#endregion

        #region 适配状态

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic"), System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
        public IEnumerable<MoblieAdaptationInfoData> GetMoblieAdaptationInfo()
        {
            throw new NotSupportedException();
        }

        //适配状态列表
        public IEnumerable<AdaptationStatus> GetAdaptationStatus()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MoblieAdaptationStatus
                             select new AdaptationStatus()
                             {
                                 AdaptationStatusID = t.AdaptationStatusID,
                                 AdaptationStatusName = t.AdaptationStatusName
                             };
                return source.ToArray();
            }
        }

        //适配状态列表
        public IEnumerable<Partners> GetPartners()
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.Partners
                             select new Partners()
                             {
                                 PartnerID = t.PartnerID,
                                 PartnerName = t.PartnerName
                             };
                return source.ToArray();
            }
        }

        public IEnumerable<MoblieAdaptationInfoData> GetAdaptationInfo(int mobileID)
        {
            using (var dc = PMSEntities.Create())
            {
                var source = from t in dc.MoblieAdaptationInfoes
                             where t.MobileID == mobileID
                             select new MoblieAdaptationInfoData
                             {
                                 AdaptationID = t.AdaptationID,
                                 AdaptationTime = t.AdaptationTime,
                                 AdaptationEndTime = t.AdaptationEndTime,
                                 AdaptationStatus = t.AdaptationStatusID,
                                 PlanUserID = t.PlanUserID
                             };
                return source.ToArray();
            }
        }
        #endregion
    }
}